$(function(){
	$(".coll_body").eq(1).show();
	$(".coll_body").eq(1).children('a').eq(1).addClass("active");
	$(".Collapsing").eq(1).children('a').children('span').addClass("rotate");
	$(".Collapsing").eq(1).click(function(){
		$(".Collapsing").eq(1).toggleClass("active");
		$(this).children('.coll_body').children('a').eq(1).toggleClass("active");
	})
//	获取url传值
	function getQueryString(name) {
		var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
		if (result == null || result.length < 1) {return "";}
			return result[1];
		}
		wid = getQueryString("wid");
//	获取预警配置列表信息
	$.ajax({
		type:"post",
		url:serverIP+"/user/warnSet/list",
		dataType:"json",
		xhrFields: {
            withCredentials: true    // 设置sessionId相同
        },
		success:function (data) {
			let result=data.data.list.result;
			var strVar = "";
			result.map(function(u){
				if(u.warnSetId==wid){
					if(u.cId){
						$("select[name='cId']").html('<option value='+u.cId+'>'+u.cName+'</option>');
					}
					if(u.brand){
						$("select[name='brand']").html('<option value='+u.brand+'>'+u.brandName+'</option>');
					}
					if(u.model){
						$("select[name='model']").html('<option value='+u.model+'>'+u.model+'</option>');
					}
					if(u.pId){
						$("select[name='pId']").html('<option value='+u.pId+'>'+u.pName+'</option>');
					}
					$('input[name="warnMinValue_01"]').val(u.kRatio);
					$('input[name="warnMinValue_02"]').val(u.cRatio);
					$('input[name="warnMinValue_03"]').val(u.mRatio);
					$('input[name="warnMinValue_04"]').val(u.yRatio);
				}
			})
		}
	})
})
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
}

$.validator.setDefaults({
    submitHandler: function() {
      	var params = $(".form-div").serialize()+"&warnSetId="+wid; 
      	console.log(params)
      	$.ajax({  
            type : "POST",  
            url : serverIP+"/user/warnSet/save",  
            data : params,  
            xhrFields: {
                withCredentials: true    // 设置sessionId相同
            },
            success : function(data) {
            	if(data.code==0){
            		alert("修改预警配置成功");
            	}else{
            		alert(data.msg);
            	}
            }  
        }); 
    }
});

$(document).ready(function() {
	$('.form-div').validate({
		rules: {
		 	warnMinValue_01: {
		 		required: true,
		 		number:true
		 	},
		 	warnMinValue_02: {
		 		required: true,
		 		number:true
		 	},
		 	warnMinValue_03: {
		 		required: true,
		 		number:true
		 	},
		 	warnMinValue_04: {
		 		required: true,
		 		number:true
		 	}
		},
		messages: {
	      	warnMinValue_01: {
	       		required: "请输入黑色墨量预警下限",
	        	number: "请输入数字"
	      	},
	      	warnMinValue_02: {
	       		required: "请输入青色墨量预警下限",
	        	number: "请输入数字"
	      	},
	      	warnMinValue_03: {
	       		required: "请输入红色墨量预警下限",
	        	number: "请输入数字"
	      	},
	      	warnMinValue_04: {
	       		required: "请输入黄色墨量预警下限",
	        	number: "请输入数字"
	      	}
		}	
	})
	
})
$(".icon-ok").click(function() {
	$(".submit").click();
})
